package org.jash.utils.net

import android.graphics.Bitmap
import android.graphics.BitmapFactory
import okhttp3.ResponseBody
import retrofit2.Converter
import retrofit2.Retrofit
import java.lang.reflect.Type

class BitmapConvertFactory private constructor():Converter.Factory() {
    companion object {
        fun create() = BitmapConvertFactory()
    }

    override fun responseBodyConverter(
        type: Type,
        annotations: Array<out Annotation>,
        retrofit: Retrofit
    ): Converter<ResponseBody, *>? = if (type == Bitmap::class.java) BitmapConvert() else null

}
class BitmapConvert:Converter<ResponseBody, Bitmap> {
    override fun convert(value: ResponseBody): Bitmap? = BitmapFactory.decodeStream(value.byteStream())
}